<template>
  <div>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="900px">
      <el-button class="bto" v-if="showAdd" type="primary" @click="openseeadd()">新增</el-button>
      <el-table :data="list" height="500" border style="width: 100%">
        <el-table-column align="center" label="权限名称">
          <template slot-scope="scope">
            <span :class="scope.row.cls">{{scope.row.purviewName}}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="权限编码">
          <template slot-scope="scope">
            <span :class="scope.row.cls">{{scope.row.purviewCode}}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="状态" v-if="Oneuse">
          <template slot-scope="scope">
            <span :class="scope.row.cls">{{scope.row.isUseStr}}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="状态" v-if="twouse">
          <template slot-scope="scope">
            <span :class="scope.row.cls">{{scope.row.isUse}}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="openseeedit(scope.row)">修改</el-button>
            <el-button type="text" style="color:#f00" @click="opendel(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <dialogRoleEdit ref="dialogRoleEdit" />
  </div>
</template>

<script>
import apisystemmenu from "@/api/baseManager/systemmenu";
import dialogRoleEdit from "./dialogAuthEdit";
import { confirm } from "@/utils/index";
export default {
  name: "dialogAuthList",
  components: { dialogRoleEdit },
  data() {
    return {
      parentId: "",
      Oneuse: false, //二级查看权限开关
      twouse: false, //一级查看权限开关
      dialogVisible: false,
      list: [],
      title: "",
      showAdd:true, //是否显示新增按钮
      menutype: false
    };
  },

  methods: {
    getList() {
      apisystemmenu
        .getAuthorityByPurviewId({ parentId: this.parentId }).then(res => {
          this.list = res.data.list;
        });
    },
    //查看
    opensee(row) {
      this.showAdd = true
      this.Oneuse = true; 
      this.twouse = false; 
      this.parentId = row.purviewId;
      this.getList();
      this.dialogVisible = true;
      this.title = "菜单名称--" + row.purviewName;
    },
    //查看一级菜单权限
    seeMenu(row) {
      this.showAdd = false
      this.title='查看一级权限'
      this.Oneuse = false; 
      this.twouse = true; 
      this.dialogVisible = true;
      apisystemmenu.getOneMenuAuthority(row).then(res => {
        this.list = res.data.list;
      });
    },
    //编辑
    openseeedit(row) {
      this.$refs.dialogRoleEdit.openseeedit(row);
    },
    //新增
    openseeadd() {
      this.$refs.dialogRoleEdit.openseeadd(this.parentId);
    },
    //删除
    opendel(row) {
      confirm("是否删除？").then(() => {
        apisystemmenu.delPurviewById(row).then(res => {
          this.$message({ type: "success", message: "删除成功！" });
          this.getList();
        });
      });
    }
  }
};
</script>

<style scoped>
.bto {
  margin-bottom: 10px;
}
</style>